home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Docs / Includes / USection.h < prev    next >
Encoding:
Text File  |  1996-04-03  |  14.1 KB  |  428 lines  |  [TEXT/MPS ]

  1. // USection.h
  2. // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __USECTION__
  5. #define __USECTION__
  6.  
  7. //----------------------------------------------------------------------------------------
  8. //  Unit: USection
  9. //
  10. //  OVERVIEW
  11. //
  12. // TSection is designed to provide Edition Manager support. TSection is an abstract
  13. // superclass which references the main Edition Manager data structure (the
  14. // SectionHandle), and a designator (designating which portion of the document is
  15. // published/ subscribed). Specialized subclasses of TSection are required to represent the
  16. // TPublisher and TSubscriber.
  17. //
  18. //  CLASS HIERARCHY
  19. //
  20. //  TSection        abstract superclass for sections
  21. //  TPublisher        an Edition Manager publisher
  22. //  TSubscriber        an Edition Manager subscriber
  23. //
  24. //  USAGE
  25. //
  26. // TPublisher/ TSubscriber is designed to be used with the Edition Manager support that is
  27. // built into MacApp. Whenever a portion of the document is publisher/ subscribed, a
  28. // TSection object is instantiated. The TSection object references a TDesignator.
  29. //----------------------------------------------------------------------------------------
  30.  
  31. // MacApp
  32.  
  33. #ifndef __ULIST__
  34. #include "UList.h"
  35. #endif
  36.  
  37. #ifndef __UOBJECT__
  38. #include "UObject.h"
  39. #endif
  40.  
  41. #ifndef __USTREAM__
  42. #include "UStream.h"
  43. #endif
  44.  
  45. // Toolbox
  46.  
  47. #ifndef __EDITIONS__
  48. #include <Editions.h>
  49. #endif
  50.  
  51.  
  52. //----------------------------------------------------------------------------------------
  53. // Forward and external class declarations. 
  54. //----------------------------------------------------------------------------------------
  55.  
  56. class TDesignator;
  57. class TEditionDocument;
  58. class TFile;
  59.  
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // Constants
  63. //----------------------------------------------------------------------------------------
  64.  
  65. const Boolean kEditionFound = TRUE;                // the edition file was found
  66.  
  67. const Boolean kEditionNotFound = FALSE;            // the edition file wasn't found
  68.  
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // passed into TSection::CancelSection()
  72. //----------------------------------------------------------------------------------------
  73.  
  74. const Boolean kCancel = TRUE;                    // cancel the section
  75.  
  76. const Boolean kDontCancel = FALSE;                // don't cancel the section
  77.  
  78.  
  79. //----------------------------------------------------------------------------------------
  80. // Section Change ID's
  81. //----------------------------------------------------------------------------------------
  82.  
  83. const ChangeID cSubscriberChanged = 610;        // change id indicating that the
  84.                                                 // subscriber changed
  85.  
  86. const ChangeID cPublisherChanged = 611;            // change id indicating that the publisher
  87.                                                 // changed
  88.  
  89.  
  90. //----------------------------------------------------------------------------------------
  91. // TSection: TSection is an abstract superclass providing common support for sections -
  92. // both subscribers and publishers.
  93. //----------------------------------------------------------------------------------------
  94.  
  95. class TSection : public TObject
  96. {
  97.     MA_DECLARE_CLASS;
  98.     
  99. public:
  100.     TEditionDocument* fDocument;                // the document that owns this section
  101.  
  102.     TDesignator* fDesignator;                    // the designated portion of the document
  103.  
  104.     SectionHandle fSectionHandle;                // reference to the section record for
  105.                                                 // this edition
  106.  
  107.     short fRsrcID;                                // rsrc id of stored form (needed for
  108.                                                 // Read)
  109.  
  110.     EditionInfoRecord fLastEditionInfo;            // stored at various points for later use
  111.  
  112.     Boolean fCanceled;                            // whether this section is canceled
  113.  
  114.     Boolean fFound;                                // whether this edition was found by
  115.                                                 // RegisterSection
  116.  
  117.     Boolean fNewSection;                        // this is a brand spankin' new section
  118.  
  119.  
  120.     //------------------------------------------------------------------------------------
  121.     //  ••• contructors/destructors •••
  122.     //------------------------------------------------------------------------------------
  123.  
  124.     TSection();
  125.         // Empty constructor to satisfy compiler.
  126.         
  127.     void ISection(TEditionDocument* itsDocument,
  128.                                  TDesignator* itsDesignator,
  129.                                  SectionHandle itsSectionHandle,
  130.                                  short itsRsrcID);
  131.         // initializes the edition object
  132.  
  133.     virtual ~TSection();
  134.         // calls Unregister, disposes the SectionHandle and AliasHandle
  135.  
  136.  
  137.     //------------------------------------------------------------------------------------
  138.     //  ••• data accessors •••
  139.     //------------------------------------------------------------------------------------
  140.  
  141.     virtual void AttachSectionHandle(SectionHandle itsSectionHandle);
  142.         // attach a SectionHandle to this TSection object
  143.  
  144.     virtual void GetEditionName(CStr255& name);
  145.         // Returns the name of the edition container file.
  146.  
  147.     //    virtual TFileHandler* GetFileHandler();
  148.     //        // returns the TFileHandler of the document with which this section is associated
  149.  
  150.     virtual SectionType GetSectionType();
  151.         // returns the (*fSectionHandle)->kind
  152.  
  153.     virtual UpdateMode GetUpdateMode();
  154.         // returns the (*fSectionHandle)->mode
  155.  
  156.  
  157.     //------------------------------------------------------------------------------------
  158.     //  ••• saving/restoring •••
  159.     //------------------------------------------------------------------------------------
  160.  
  161.     virtual void DoWrite(TFile* aFile, Boolean makingCopy);
  162.         // writes the section handle as a sect resource and the alias handle as a alis
  163.         // resource
  164.  
  165.     virtual void DoRead(TFile* aFile);
  166.         // reads the section handle from a sect resource and the alias handle from a alis
  167.         // resource
  168.  
  169.     virtual void DoNeedDiskSpace(long& dataForkBytes, long& rsrcForkBytes);
  170.         // Bytes required to store saved sections on disk. When called, both parameters
  171.         // are set to 0 for you.
  172.  
  173.     virtual void Associate(TFile* aFile);
  174.         // call this to associate the section handle with a new section document
  175.  
  176.  
  177.     //------------------------------------------------------------------------------------
  178.     // ••• miscellaneous •••
  179.     //------------------------------------------------------------------------------------
  180.  
  181.     virtual void Delete();
  182.         // removes the section resources
  183.  
  184.     virtual TFile* GetCurrentFile(TFile* aFile);
  185.         // given a file being written to in DoWrite, this returns the correct file
  186.  
  187.     virtual Boolean IsCanceled();
  188.         // returns fCanceled
  189.  
  190.     virtual Boolean IsChanged();
  191.         // returns true if the mdDate of the SectionRecord is newer than the mdDate of the
  192.         // edition on disk
  193.  
  194.     virtual Boolean IsRegistered();
  195.         // returns true if fRegistered & (IsRegisteredSection returns noErr)
  196.  
  197.     virtual void MarkAsChanged();
  198.         // marks this publisher as changed; should be called each time the user edits the
  199.         // data in the publisher
  200.  
  201.     virtual OSErr Register();
  202.         // calls RegisterSection on the Section Handle and sets fRegisteredSection
  203.  
  204.     virtual void UnRegister();
  205.         // calls UnRegisterSection on the Section Handle and sets fRegisteredSection
  206.  
  207.     virtual void UpdateEditionInfo();
  208.         // updates fEditionInfo for later use
  209.  
  210.     virtual void CancelSection(Boolean cancel);
  211.         // if cancel is true then calls UnRegister and sets fCanceled to true else if
  212.         // cancel is false then calls Register and sets fCanceled to false
  213. };
  214.  
  215.  
  216. //----------------------------------------------------------------------------------------
  217. // TPublisher: each instance of this class represents a part of the document that is
  218. // published
  219. //----------------------------------------------------------------------------------------
  220.  
  221. class TPublisher : public TSection
  222. {
  223.     MA_DECLARE_CLASS;
  224.     
  225. public:
  226.  
  227.     //------------------------------------------------------------------------------------
  228.     //  ••• contructors/destructors •••
  229.     //------------------------------------------------------------------------------------
  230.  
  231.     TPublisher();
  232.         // Empty constructor to satisfy compiler.
  233.     virtual ~TPublisher();
  234.         // Destructor
  235.         
  236.     void IPublisher(TEditionDocument* itsDocument,
  237.                                    TDesignator* itsDesignator,
  238.                                    SectionHandle itsSectionHandle,
  239.                                    short itsRsrcID);
  240.         // initializes a publisher object
  241.  
  242.  
  243.     //------------------------------------------------------------------------------------
  244.     //  ••• change notification •••
  245.     //------------------------------------------------------------------------------------
  246.  
  247.     virtual void DoUpdate(ChangeID theChange,
  248.                                  TObject* changedObject,
  249.                                  TObject* changedBy,
  250.                                  TDependencySpace* dependencySpace);
  251.         // marks this publisher as changed calling MarkAsChanged
  252.  
  253.  
  254.     //------------------------------------------------------------------------------------
  255.     //  ••• saving/restoring •••
  256.     //------------------------------------------------------------------------------------
  257.  
  258.     virtual void Publish(TFile* aFile);
  259.         // publishes this edition to the edition file
  260.  
  261.     virtual void DoWrite(TFile* aFile, Boolean makingCopy);
  262.     // calls INHERITTED Write if (mode is pumOnSave) & IsChanged then Publish
  263.  
  264.  
  265.     //------------------------------------------------------------------------------------
  266.     //  ••• miscellaneous •••
  267.     //------------------------------------------------------------------------------------
  268.  
  269.     virtual void Delete();
  270.         // deletes the edition file; called when the doc is saved if the user canceled the
  271.         // publisher
  272.  
  273.     virtual void DeleteEditionFile();
  274.         // delete the edition container file
  275.  
  276.     virtual Boolean IsChanged();
  277.         // returns true if the mdDate of the SectionRecord is newer than the mdDate of the
  278.         // edition on disk
  279.  
  280.     virtual void MarkAsChanged();
  281.         // marks this publisher as changed; should be called each time the user edits the
  282.         // data in the publisher
  283.  
  284. };
  285.  
  286.  
  287. //----------------------------------------------------------------------------------------
  288. // TSubscriber - each instance represents a subscriber for this document.
  289. //----------------------------------------------------------------------------------------
  290.  
  291. class TSubscriber : public TSection
  292. {
  293.     MA_DECLARE_CLASS;
  294.     
  295. public:
  296.     Boolean            fChanged;                    // whether or not this guy has changed.
  297.  
  298.     //------------------------------------------------------------------------------------
  299.     //  ••• contructors/destructors •••
  300.     //------------------------------------------------------------------------------------
  301.  
  302.     TSubscriber();
  303.         // Empty constructor to satisfy compiler.
  304.     virtual ~TSubscriber();
  305.         // Destructor
  306.         
  307.     void ISubscriber(TEditionDocument* itsDocument,
  308.                                     TDesignator* itsDesignator,
  309.                                     SectionHandle itsSectionHandle,
  310.                                     short itsRsrcID);
  311.         // initializes the subscriber object
  312.  
  313.  
  314.     //------------------------------------------------------------------------------------
  315.     //  ••• saving/restoring •••
  316.     //------------------------------------------------------------------------------------
  317.  
  318.     virtual void Subscribe();
  319.         // updates this subscriber from the edition on disk
  320.  
  321.     virtual void SubscribeIfNewer();
  322.         // calls Subscribe if a newer edition is available
  323.  
  324.  
  325.     //------------------------------------------------------------------------------------
  326.     //  ••• miscellaneous •••
  327.     //------------------------------------------------------------------------------------
  328.  
  329.     virtual Boolean IsNewerEditionAvailable();
  330.         // return true if there is a newer version of this edition on disk
  331.  
  332.     virtual void OpenPublisher();
  333.         // calls GetEditionInfo & GotoPublisherSection
  334.  
  335.     virtual Boolean IsChanged();
  336.         // returns true if the mdDate of the SectionRecord is newer than the mdDate of the
  337.         // edition on disk
  338.  
  339.     virtual void MarkAsChanged();
  340.         // marks this publisher as changed; should be called each time the user edits the
  341.         // data in the publisher
  342. };
  343.  
  344.  
  345. //----------------------------------------------------------------------------------------
  346. // TSectionStream reads data from and writes data to an already open EditionContainerFile.
  347. // Should be enhanced to support streaming data concurrently of various OS Types (e.g.
  348. // PICT, TEXT, etc) rather than simply streaming one type at a time.
  349. //----------------------------------------------------------------------------------------
  350.  
  351. class TSectionStream : public TStream
  352. {
  353.     MA_DECLARE_CLASS;
  354.     
  355. public:
  356.     EditionRefNum fEditionRefNum;                // refnum of EditionContainerFile
  357.  
  358.     OSType fEditionOSType;                        // OSType to write to EditionContainerFile
  359.  
  360.     long fPosition;                                // offset into the EditionContainerFile
  361.  
  362.     long fSize;                                    // size of the fEditionOSType
  363.  
  364.     //------------------------------------------------------------------------------------
  365.     //  ••• contructors/destructors •••
  366.     //------------------------------------------------------------------------------------
  367.  
  368.     TSectionStream();
  369.         // Constructor
  370.     virtual ~TSectionStream();
  371.         // Destructor
  372.         
  373.     void ISectionStream(EditionRefNum itsEditionRefNum, OSType itsEditionOSType);
  374.         // Initialize the TSectionStream.
  375.  
  376.     //------------------------------------------------------------------------------------
  377.     //  ••• miscellaneous •••
  378.     //------------------------------------------------------------------------------------
  379.  
  380.     virtual void Reset(OSType itsEditionOSType, long itsSize);
  381.         // Resets fPosition to 0, fEditionOSType to itsEditionOSType, and fSize to
  382.         // itsSize.
  383.  
  384.     virtual long GetPosition();
  385.         // Returns fPosition.
  386.  
  387.     virtual void SetPosition(long newPosition);
  388.         // Sets fPosition.
  389.  
  390.     virtual long GetSize();
  391.         // Returns fSize.
  392.  
  393.     virtual void SetSize(long newSize);
  394.         // Sets fSize.
  395.  
  396.     virtual void ReadBytes(void* p, long count);
  397.         // Reads bytes from the Edition Container File.
  398.  
  399.     virtual void WriteBytes(const void* p, long count);
  400.         // Write bytes to the Edition Container File.
  401. };
  402.  
  403. //----------------------------------------------------------------------------------------
  404. // TSectionList: Subclass of TSortedList that manages a sorted list of TSection objects.
  405. //----------------------------------------------------------------------------------------
  406.  
  407. class TSectionList : public TSortedList
  408. {
  409.     MA_DECLARE_CLASS;
  410.     
  411. public:
  412.  
  413.     TSectionList();
  414.         // Empty constructor to satisfy compiler.
  415.     virtual ~TSectionList();
  416.         // Destructor
  417.         
  418.     void ISectionList();
  419.         // Initialize the list
  420.  
  421.     virtual CompareResult Compare(TObject* item1, TObject* item2);
  422.         // Compares 'item'1 with 'item2' returning an integer indicating the results of
  423.         // the comparison
  424.  
  425. };
  426.  
  427. #endif // __USECTION__
  428.